package com.fourinone.bean;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * @Description
 * @auther Szper
 * @create 2019-10-18 14:04
 */
public class ResourceBean {
    protected String resourcesName; //源文件名称
    protected ResourceBundle bundle; //解决国际化和本地化
    public ResourceBean(){}

    public ResourceBean(String resourcesName)
    {
        bundle = ResourceBundle.getBundle(resourcesName);
    }
    public ResourceBean(String resourcesName, Locale locale) {
        bundle = ResourceBundle.getBundle(resourcesName, locale);
    }
    public String getString(String keyWord)
    {
        String str = "";
        try
        {
            str = bundle.getString(keyWord);
        }
        catch(MissingResourceException ex)
        {
            System.err.println(ex);
        }
        return str;
    }

    public static void main(String[] args)
    {
        ResourceBean rb = new ResourceBean("config", new Locale("en", "US"));
        System.out.println(rb.getString("QSXYSJ"));
        System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
        System.out.println(ResourceBean.class.getClassLoader().getResource(""));
        System.out.println(ClassLoader.getSystemResource(""));
        System.out.println(ResourceBean.class.getResource(""));
        System.out.println(ResourceBean.class.getResource("/"));
        System.out.println(new java.io.File("").getAbsolutePath());
        System.out.println(System.getProperty("user.dir"));
    }
}
